package com.dss.auto_deploy.listener;

import com.alibaba.fastjson.JSON;
import com.dss.auto_deploy.domain.Deploy;
import com.dss.auto_deploy.event.UploadAndStartEvent;
import com.dss.auto_deploy.service.IDeployService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @Description:
 * @author: dongshoushan
 */
@Slf4j
@Component
@AllArgsConstructor
public class UploadAndStartListener {
    @Resource
    private IDeployService deployService;

    @Async
    @Order
    @EventListener(UploadAndStartEvent.class)
    public void run(UploadAndStartEvent event) throws IOException {
        Deploy deploy = event.getDeploy();
        String[] split = event.getSplit();
        log.info("==============开始上传事件触发:{}=================", JSON.toJSONString(deploy));
        deployService.startService(deploy,split);
    }
}
